package com.ruoyi.web.controller.tool;


import java.util.List;

import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.jdcloud.sdk.auth.CredentialsProvider;
import com.jdcloud.sdk.auth.StaticCredentialsProvider;
import com.jdcloud.sdk.http.HttpRequestConfig;
import com.jdcloud.sdk.http.Protocol;
import com.jdcloud.sdk.service.sms.client.SmsClient;
import com.jdcloud.sdk.service.sms.model.BatchSendRequest;
import com.jdcloud.sdk.service.sms.model.BatchSendResponse;

@Service
public class SmsSender {
	private SmsClient smsClient;
    private static String region = "cn-north-1";
	
	public SmsSender() {
		/**
                * 普通用户aksk （应用管理-概览 页面可以查看自己aksk）
         */
    	String accessKeyId = "354B34A1A3B74F976DD230D60869FE1F";
        String secretAccessKey = "F5C48E13FCEA6F403934BCE135C07326";

        CredentialsProvider credentialsProvider = new StaticCredentialsProvider(accessKeyId, secretAccessKey);
        this.smsClient = SmsClient.builder()
                .credentialsProvider(credentialsProvider)
                .httpRequestConfig(new HttpRequestConfig.Builder().protocol(Protocol.HTTP).build()) //默认为HTTPS
                .build();
	}
	
	/**
     * 发送
     */
    public String batchSendMsg(String phone,String code) {
        BatchSendRequest request = new BatchSendRequest();
        request.setRegionId(region);
        request.setTemplateId("bm_02623e8a7929438896b2345a17ca02d5");
        //request.setSignId("qm_6b8176fd50f344c28cff39e0ab7f2a4f");
        request.setSignId("qm_b9fe50cdf2f94e16ad743337d93763ad");
        List<String> phoneList = Lists.newArrayList();
        phoneList.add(phone);
        request.setPhoneList(phoneList);
        List<String> paramsList = Lists.newArrayList();
        paramsList.add(code);
        //模板参数，根据需要传入
        request.setParams(paramsList);
        BatchSendResponse response = smsClient.batchSend(request);
        return new Gson().toJson(response);
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SmsSender sms=new SmsSender();
		sms.batchSendMsg("343422","");
	}

}
